<div class="git-per-tags-branches-permissions">
    <h3>{{ fine_grained_permissions_title }}</h3>

    <div class="fine-grained-permissions">
        <label class="checkbox">
            <input type="checkbox"
                   name="use-fine-grained-permissions"
                   class="toggle-fine-grained-permissions"
                   id="use-fine-grained-permissions"
                {{# are_fine_grained_permissions_defined }}
                   checked="checked" {{/ are_fine_grained_permissions_defined }}
                {{ disabled }}
            /> {{ fine_grained_permissions_checkbox_label }}
        </label>

        {{# are_regexp_permission_activated_at_site_level }}
            <div class="regexp_permission_activated">
                <span class="use-regexp-label-arrow">&#8627;</span>
                <label class="checkbox use-regexp-label">
                    <input type="checkbox"
                           name="use-regexp"
                           class="use-regexp"
                           {{# is_regexp_enabled }} checked="checked" {{/ is_regexp_enabled }}
                    />
                    <p class="regexp_permission_label">{{ regexp_permission_label }}</p>
                </label>
                <p class="text-warning regexp_incoherence_label">
                    <i class="icon-warning-sign"> </i>
                    {{ regexp_incoherence_label }}
                </p>
            </div>
        {{/ are_regexp_permission_activated_at_site_level }}
    </div>

    {{# are_fine_grained_permissions_defined }}
        {{# is_fork }}
            <p class="alert">{{ fine_grained_permissions_fork_warning }}</p>
        {{/ is_fork }}

        <h4>{{ branches_title }}</h4>
        <table class="table table-bordered git-permission-table git-fine-grained-permissions-branch">
            <thead>
            <tr>
                <th>{{ pattern_column }}</th>
                <th class="git-permission-table-selector">{{ label_write }}</th>
                <th class="git-permission-table-selector">{{ label_rw }}</th>
                {{^ is_fork }}
                    <th>{{ actions_column }}</th>
                {{/ is_fork }}
            </tr>
            </thead>
            <tbody>
            {{^ has_branches_permissions }}
                <tr class="empty-table">
                    <td {{^ is_fork }}colspan="4"{{/ is_fork }}
                        {{# is_fork }}colspan="3"{{/ is_fork }}
                    >{{ empty }}</td>
                </tr>
            {{/ has_branches_permissions }}

            {{# has_branches_permissions }}
                {{# branches_permissions }}
                    <tr>
                        <td class="permission-pattern">{{ pattern }}</td>
                        <td class="permission-write">
                            <select multiple="multiple" size="6" name="edit-branch-write[{{ id }}][]" {{ disabled }}>
                                {{# writers }}
                                    <option value="{{ value }}" {{{ selected }}}>{{ label }}</option>
                                {{/ writers }}
                            </select>
                        </td>
                        <td class="permission-rewind">
                            <select multiple="multiple" size="6" name="edit-branch-rewind[{{ id }}][]" {{ disabled }}>
                                {{# rewinders }}
                                    <option value="{{ value }}" {{{ selected }}}>{{ label }}</option>
                                {{/ rewinders }}
                            </select>
                        </td>
                        {{^ is_fork }}
                            <td class="permission-delete">
                                <a href="javascript:;"
                                   class="remove-fine-grained-permission"
                                   data-toggle="popover"
                                   data-trigger="click"
                                   data-placement="left"
                                   data-html="true"
                                   data-popover-id="remove-{{ id }}-popover"
                                   data-form-action="{{ remove_form_action }}"
                                >
                                    <i class="icon-trash"></i> {{ remove_fine_grained_permission_delete }}

                                </a>
                                {{> settings/popover-remove-fine-grained-permission }}
                            </td>
                        {{/ is_fork }}
                    </tr>
                {{/ branches_permissions }}
            {{/ has_branches_permissions }}
            </tbody>
        </table>
        {{^ is_fork }}
            <button class="btn add-fine-grained-permission"
                    data-type="branch"
                    data-regexp-enabled="{{ is_regexp_enabled }}">
                {{ add_branch_permission }}
            </button>
        {{/ is_fork }}

        <h4>{{ tags_title }}</h4>
        <table class="table table-bordered git-permission-table git-fine-grained-permissions-tag">
            <thead>
            <tr>
                <th>{{ pattern_column }}</th>
                <th class="git-permission-table-selector">{{ label_write }}</th>
                <th class="git-permission-table-selector">{{ label_rw }}</th>
                {{^ is_fork }}
                    <th>{{ actions_column }}</th>
                {{/ is_fork }}
            </tr>
            </thead>
            <tbody>
            {{^ has_tags_permissions }}
                <tr class="empty-table">
                    <td {{^ is_fork }}colspan="4"{{/ is_fork }}
                        {{# is_fork }}colspan="3"{{/ is_fork }}
                    >{{ empty }}</td>
                </tr>
            {{/ has_tags_permissions }}

            {{# has_tags_permissions }}
                {{# tags_permissions }}
                    <tr>
                        <td class="permission-pattern">{{ pattern }}</td>
                        <td class="permission-write">
                            <select multiple="multiple" size="6" name="edit-tag-write[{{ id }}][]" {{ disabled }}>
                                {{# writers }}
                                    <option value="{{ value }}" {{{ selected }}}>{{ label }}</option>
                                {{/ writers }}
                            </select>
                        </td>
                        <td class="permission-rewind">
                            <select multiple="multiple" size="6" name="edit-tag-rewind[{{ id }}][]" {{ disabled }}>
                                {{# rewinders }}
                                    <option value="{{ value }}" {{{ selected }}}>{{ label }}</option>
                                {{/ rewinders }}
                            </select>
                        </td>
                        {{^ is_fork }}
                            <td class="permission-delete">
                                <a href="javascript:;"
                                   class="remove-fine-grained-permission"
                                   data-toggle="popover"
                                   data-trigger="click"
                                   data-placement="left"
                                   data-html="true"
                                   data-popover-id="remove-{{ id }}-popover"
                                   data-form-action="{{ remove_form_action }}"
                                >
                                    <i class="icon-trash"></i> {{ remove_fine_grained_permission_delete }}
                                </a>
                                {{> settings/popover-remove-fine-grained-permission }}
                            </td>
                        {{/ is_fork }}
                    </tr>
                {{/ tags_permissions }}
            {{/ has_tags_permissions }}
            </tbody>
        </table>
        {{^ is_fork }}
            <button
                    class="btn add-fine-grained-permission"
                    data-type="tag"
                    data-regexp-enabled="{{ is_regexp_enabled }}">
                {{ add_tag_permission }}
            </button>
        {{/ is_fork }}

    {{/ are_fine_grained_permissions_defined }}
</div>

<select id="add-fine-grained-permission-template" class="plugin_git_permissions_select" multiple="multiple" size="6">
    {{# new_fine_grained_ugroups }}
        <option value="{{ value }}" {{{ selected }}}>{{ label }}</option>
    {{/ new_fine_grained_ugroups }}
</select>

<div id="modal-regexp-delete" class="modal modal-regexp-delete fade in">
    {{> settings/popover-remove-non-valid-regexp-permission }}
</div>
